﻿using ZYCommon;
using System;

namespace TextEditor
{
    

    public class A_SetUserLevel : A_Action
    {
        internal int intLevelBack = 0;

        public override string ActionName()
        {
            return "setuserlevel";
        }

        public override A_Action Clone()
        {
            A_SetUserLevel level = new A_SetUserLevel();
            level.BaseCloneFrom(this);
            level.intLevelBack = this.intLevelBack;
            return level;
        }

        public override bool Execute()
        {
            int num = StringCommon.ToInt32Value(base.Param1, -1);
            if (num != base.myOwnerDocument.Info.VisibleUserLevel)
            {
                this.intLevelBack = base.myOwnerDocument.Info.VisibleUserLevel;
                base.myOwnerDocument.Info.VisibleUserLevel = num;
                base.myOwnerDocument.RefreshElements();
                base.myOwnerDocument.RefreshLine();
                base.myOwnerDocument.UpdateView();
                base.myOwnerDocument.RegisterUndo(this);
            }
            return true;
        }

        public override bool isUndoable()
        {
            return true;
        }

        public override bool Undo()
        {
            base.myOwnerDocument.Info.VisibleUserLevel = this.intLevelBack;
            base.myOwnerDocument.RefreshElements();
            base.OwnerDocument.RefreshSize();
            base.myOwnerDocument.RefreshLine();
            base.myOwnerDocument.UpdateView();
            return true;
        }

        public override string UndoName()
        {
            return ("设置显示层次" + this.intLevelBack.ToString());
        }
    }
}

